package cn.gson.springboot.model.service;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;

import cn.gson.springboot.model.dao.SectionDAO;
import cn.gson.springboot.model.mapper.SectionMapper;
import cn.gson.springboot.model.pojos.Section;
import cn.gson.springboot.model.vo.SectionVo;

@Service
@Transactional(rollbackFor=Exception.class)
public class SectionService {
	
	@Autowired
	private SectionMapper smapper;
	
	@Autowired
	private SectionDAO sdao;
	
	//查询所有或名字查询
	public List<Section> selectAllsection(Integer sectionid,String sectiontype){
		return (List<Section>) smapper.selectAllsection(sectionid,sectiontype);
	}
	
	public JSONArray selectAllsectionjson(Integer  sectionId) {
		return smapper.selectAllsectionjson(sectionId);
	}
	
	//根据科室id查询
	public Section findsetionByid(Integer setionid) {
		if(sdao.existsById(setionid)) {
			return sdao.findById(setionid).get();
		}
		return null;
	}
	
	//科室新增
	public  void add_section(SectionVo sectionvo) {
		List<Section> section = sectionvo.getSection();
		for (int i = 0; i < section.size(); i++) {
			smapper.addsection(section.get(i).getSectionName(),section.get(i).getSectionPrice(),section.get(i).getSectionType());
		}
	}
}
